#!/bin/bash

## The point of this script is to add ips to the ignore list
## So that they don't need to be in my git hosted filters.

## ./f2b_ignore_ip.sh [add|del] [ip1] [ip2]...

if [ $UID -ne 0 ]; then
    echo "Run as root"
    exit
fi

if [ -z "$*" ]; then
    echo "No augments"
    exit
fi

if [ $1 != "del" ] && [ $1 != "add" ]; then
    echo "Bad option"
    exit
fi

act=$1
shift       ## Remove the add/del
ips=$*
jails=$(fail2ban-client status | gawk '/list/ {match($0, /\t(.*)$/, m)}; END {gsub(",","",m[1]);print m[1]}')

for j in $jails; do
    for i in $ips;do
        fail2ban-client set $j ${act}ignoreip $i
    done
done
